package com.android.lovingpet.util;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.Button;

import com.android.lovingpet.R;


/**
 * Created by ikata on 2018/2/13.
 */

public class TimeCount extends CountDownTimer {
    private Context mContext;
    private Button button;
    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public TimeCount(Context context, Button button, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.mContext=context;
        this.button=button;
    }
    @Override
    public void onTick(long millisUntilFinished) {
        button.setBackgroundResource(R.drawable.button_yj5);
        button.setTextColor(mContext.getResources().getColor(R.color.colorGray1));
        button.setClickable(false);
        button.setText(millisUntilFinished / 1000 +" 秒");
    }
    @Override
    public void onFinish() {
        button.setText("重新获取");
        button.setClickable(true);
        button.setBackgroundResource(R.drawable.button_yj4);
        button.setTextColor(mContext.getResources().getColor(R.color.colorRed1));
    }
}
